#!/usr/bin/python
# -*- coding : UTF-8 -*-
# ========================
# @Time  : 2020/6/4 10:38
# @Author: Mecell
# @File  : asset_param.py
# ========================

import re
import json

from common.path_constants import ASSET_MANAGE_YAML
from data.com_function import select_random_item
from common.yaml_packaging import YamlHandle
from database.asset_mysql import AssetMysql
from common.mysql_packaging import MysqlHandle
from common.context_packaging import ContextHandle
from parameterize.user_param import UserContextHandle as UserContext



class AssetContextHandle(ContextHandle):
    """
    定义资产管理参数化，反射功能的类
    """

    @classmethod
    def rep_asset_id(cls, data):
        """
        替换资产id
        :param data:
        :return:
        """
        last_asset_id_pattern = re.compile(eval(cls.re_config("asset","last_asset_id")))
        storage_asset_class_id_pattern = re.compile(eval(cls.re_config("asset","storage_asset_class_id")))
        storage_asset_name_id_pattern = re.compile(eval(cls.re_config("asset","storage_asset_name_id")))
        asset_mysql = AssetMysql()
        if re.search(last_asset_id_pattern, data):
            rep_last_asset_id = getattr(cls, 'asset_id')
            data = re.sub(last_asset_id_pattern, str(rep_last_asset_id), data)
        if re.search(storage_asset_class_id_pattern, data):
            rep_storage_asset_class_id = asset_mysql.get_storage_asset_class_id().get("asset_classification")
            data = re.sub(storage_asset_class_id_pattern, str(rep_storage_asset_class_id), data)
        if re.search(storage_asset_name_id_pattern, data):
            rep_storage_asset_name_id = asset_mysql.get_storage_asset_name_id().get("asset_name")
            data = re.sub(storage_asset_name_id_pattern, str(rep_storage_asset_name_id), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_asset_encoding(cls, data):
        """
        替换资产编码
        :param data:
        :return:
        """
        last_asset_encoding_pattern = re.compile(eval(cls.re_config("asset", "last_asset_encoding")))
        if re.search(last_asset_encoding_pattern, data):
            rep_last_asset_encoding = getattr(cls, 'asset_encoding')
            data = re.sub(last_asset_encoding_pattern, str(rep_last_asset_encoding), data)
        return data

    @classmethod
    def rep_asset_class_info(cls, data):
        """
        替换资产分类信息
        :param data:
        :return:
        """
        asset_id_pattern = re.compile(eval(cls.re_config("asset", "asset_id")))
        asset_parent_id_pattern = re.compile(eval(cls.re_config("asset", "asset_parent_id")))
        asset_class_code_pattern = re.compile(eval(cls.re_config("asset", "asset_class_code")))
        asset_mysql = AssetMysql()
        class_info = asset_mysql.get_all_asset_class()
        if re.search(asset_id_pattern, data):
            rep_asset_id = class_info.get("assets_id")
            data = re.sub(asset_id_pattern, str(rep_asset_id), data)
        if re.search(asset_parent_id_pattern, data):
            rep_asset_parent_id = class_info.get("assets_parent_id")
            data = re.sub(asset_parent_id_pattern, str(rep_asset_parent_id), data)
        if re.search(asset_class_code_pattern, data):
            rep_class_code = class_info.get("assets_classify_code")
            data = re.sub(asset_class_code_pattern, rep_class_code, data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_dept_area(cls, data):
        """
        替换资产存储区域、部门和地址
        :param emp_num:
        :return:
        """
        dept_id_pattern = re.compile(eval(cls.re_config("dept area", "dept_id")))
        dept_name_pattern = re.compile(eval(cls.re_config("dept area", "dept_name")))
        area_id_pattern = re.compile(eval(cls.re_config("dept area", "area_id")))
        area_name_pattern = re.compile(eval(cls.re_config("dept area", "area_name")))
        cur_dept_area_id_pattern = re.compile(eval(cls.re_config("dept area", "cur_dept_area_id")))
        cur_dept_area_name_pattern = re.compile(eval(cls.re_config("dept area", "cur_dept_area_name")))
        asset_mysql = AssetMysql()
        dept_area = asset_mysql.get_storage_place()
        if re.search(dept_id_pattern, data):
            rep_dept_id = dept_area.get('dept_id')
            data = re.sub(dept_id_pattern, str(rep_dept_id), data)
        if re.search(dept_name_pattern, data):
            rep_dept_name = dept_area.get('department_name')
            data = re.sub(dept_name_pattern, rep_dept_name, data)
        if re.search(area_id_pattern, data):
            rep_area_id = dept_area.get('max_dept_area')
            data = re.sub(area_id_pattern, str(rep_area_id), data)
        if re.search(cur_dept_area_id_pattern, data):
            rep_dept_area_id = dept_area.get('dept_area_id')
            data = re.sub(cur_dept_area_id_pattern, str(rep_dept_area_id), data)
        if re.search(area_name_pattern, data):
            rep_area_name = dept_area.get('area_name')
            data = re.sub(area_name_pattern, rep_area_name, data)
        if re.search(cur_dept_area_name_pattern, data):
            rep_cur_dept_area_name = dept_area.get('area_name')
            data = re.sub(cur_dept_area_name_pattern, rep_cur_dept_area_name, data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_dept_area_id(cls, data):
        """
        替换部门区域id
        :param data:
        :return:
        """
        dept_area_id_pattern = re.compile(eval(cls.re_config("dept area", "dept_area_id")))
        asset_mysql = AssetMysql()
        if re.search(dept_area_id_pattern, data):
            rep_dept_area_id = getattr(cls, 'dept_area_id')
            data = re.sub(dept_area_id_pattern, str(rep_dept_area_id), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_asset_info(cls, data):
        """
        替换资产信息
        :param data:
        :return:
        """
        asset_area_id_pattern = re.compile(eval(cls.re_config("asset", "asset_area_id")))
        asset_dept_id_pattern = re.compile(eval(cls.re_config("asset", "asset_dept_id")))
        asset_place_id_pattern = re.compile(eval(cls.re_config("asset", "asset_place_id")))
        asset_place_name_pattern = re.compile(eval(cls.re_config("asset", "asset_place_name")))
        asset_state_id_pattern = re.compile(eval(cls.re_config("asset", "asset_state_id")))
        asset_name_id_pattern = re.compile(eval(cls.re_config("asset", "asset_name_id")))
        asset_class_id_pattern = re.compile(eval(cls.re_config("asset", "asset_class_id")))
        purchase_date_pattern = re.compile(eval(cls.re_config("asset", "purchase_date")))
        asset_encoding_pattern = re.compile(eval(cls.re_config("asset", "asset_encoding")))
        asset_mysql = AssetMysql()
        asset_info = asset_mysql.get_asset_info()
        if re.search(asset_area_id_pattern, data):
            rep_asset_area_id = asset_info.get('max_dept_area')
            data = re.sub(asset_area_id_pattern, str(rep_asset_area_id), data)
        if re.search(asset_dept_id_pattern, data):
            rep_asset_dept_id = asset_info.get('dept_id')
            data = re.sub(asset_dept_id_pattern, str(rep_asset_dept_id), data)
        if re.search(asset_place_id_pattern, data):
            rep_asset_place_id = asset_info.get('dept_area_id')
            data = re.sub(asset_place_id_pattern, str(rep_asset_place_id), data)
        if re.search(asset_place_name_pattern, data):
            rep_asset_place_name = asset_info.get('min_dept_area')
            data = re.sub(asset_place_name_pattern, str(rep_asset_place_name), data)
        if re.search(asset_state_id_pattern, data):
            rep_asset_state_id = asset_info.get('state_lock')
            data = re.sub(asset_state_id_pattern, str(rep_asset_state_id), data)
        if re.search(asset_name_id_pattern, data):
            rep_asset_name_id = asset_info.get('asset_name')
            data = re.sub(asset_name_id_pattern, str(rep_asset_name_id), data)
        if re.search(asset_class_id_pattern, data):
            rep_asset_class_id = asset_info.get('asset_classification')
            data = re.sub(asset_class_id_pattern, str(rep_asset_class_id), data)
        if re.search(purchase_date_pattern, data):
            rep_purchase_date = asset_info.get('purchase_date')
            data = re.sub(purchase_date_pattern, str(rep_purchase_date), data)
        if re.search(asset_encoding_pattern, data):
            rep_asset_encoding = asset_info.get('assets_encoding')
            data = re.sub(asset_encoding_pattern, str(rep_asset_encoding), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_bottom_asset_class(cls, data):
        """
        替换资产分类和资产名称
        :param data:
        :return:
        """
        ad_asset_name_id_pattern = re.compile(eval(cls.re_config("asset", "ad_asset_name_id")))
        ad_asset_class_id_pattern = re.compile(eval(cls.re_config("asset", "ad_asset_class_id")))
        asset_mysql = AssetMysql()
        asset_info = asset_mysql.get_bottom_asset_class()
        if re.search(ad_asset_name_id_pattern, data):
            rep_asset_name_id = asset_info.get('assets_id')
            data = re.sub(ad_asset_name_id_pattern, str(rep_asset_name_id), data)
        if re.search(ad_asset_class_id_pattern, data):
            rep_asset_class_id = asset_info.get('assets_parent_id')
            data = re.sub(ad_asset_class_id_pattern, str(rep_asset_class_id), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_user_dept_emp(cls, data):
        """
        替换使用部门ID和使用人信息
        :param data:
        :return:
        """
        user_dept_id_pattern = re.compile(eval(cls.re_config("asset", "user_dept_id")))
        user_address_id_pattern = re.compile(eval(cls.re_config("asset", "user_address_id")))
        user_emp_num_pattern = re.compile(eval(cls.re_config("asset", "user_emp_num")))
        user_emp_name_pattern = re.compile(eval(cls.re_config("asset", "user_emp_name")))
        mysql_obj = MysqlHandle()
        cur_emp_info = mysql_obj.get_cur_emp_info()
        if re.search(user_dept_id_pattern, data):
            rep_user_dept_id = cur_emp_info.get('department_id')
            data = re.sub(user_dept_id_pattern, str(rep_user_dept_id), data)
        if re.search(user_address_id_pattern, data):
            rep_user_address_id = cur_emp_info.get('dept_area_id')
            data = re.sub(user_address_id_pattern, str(rep_user_address_id), data)
        if re.search(user_emp_num_pattern, data):
            rep_user_emp_num = cur_emp_info.get('job_number')
            data = re.sub(user_emp_num_pattern, str(rep_user_emp_num), data)
        if re.search(user_emp_name_pattern, data):
            rep_user_emp_name = cur_emp_info.get('emp_name')
            data = re.sub(user_emp_name_pattern, str(rep_user_emp_name), data)
        mysql_obj.close_sql()
        return data

    @classmethod
    def rep_unmatched_user_dept_emp(cls, data):
        """
        替换使用部门ID和使用人所在部门不匹配信息
        :param data:
        :return:
        """
        un_user_dept_id_pattern = re.compile(eval(cls.re_config("asset", "un_user_dept_id")))
        un_user_emp_num_pattern = re.compile(eval(cls.re_config("asset", "un_user_emp_num")))
        un_user_emp_name_pattern = re.compile(eval(cls.re_config("asset", "un_user_emp_name")))
        asset_mysql = AssetMysql()
        cur_emp_info = asset_mysql.get_unmatched_emp_dept()
        if re.search(un_user_dept_id_pattern, data):
            rep_un_user_dept_id = cur_emp_info.get('department_id')
            data = re.sub(un_user_dept_id_pattern, str(rep_un_user_dept_id), data)
        if re.search(un_user_emp_num_pattern, data):
            rep_un_user_emp_num = cur_emp_info.get('job_number')
            data = re.sub(un_user_emp_num_pattern, str(rep_un_user_emp_num), data)
        if re.search(un_user_emp_name_pattern, data):
            rep_un_user_emp_name = cur_emp_info.get('emp_name')
            data = re.sub(un_user_emp_name_pattern, str(rep_un_user_emp_name), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_asset_state(cls, data):
        """
        替换资产状态
        :param data:
        :return:
        """
        state_lock_pattern = re.compile(eval(cls.re_config("asset", "state_lock")))
        unlock_state_pattern = re.compile(eval(cls.re_config("asset", "unlock_state")))
        if re.search(state_lock_pattern, data):
            rep_state_lock = AssetMysql.get_asset_state()
            data = re.sub(state_lock_pattern, str(rep_state_lock), data)
        if re.search(unlock_state_pattern, data):
            rep_unlock_state = AssetMysql.get_unlock_asset_state()
            data = re.sub(unlock_state_pattern, str(rep_unlock_state), data)
        return data

    @classmethod
    def rep_check_asset_storage(cls, data):
        """
        替换导入资产数据
        :param data:
        :return:
        """
        check_asset_storage_pattern = re.compile(eval(cls.re_config("asset", "check_asset_storage")))
        if re.search(check_asset_storage_pattern, data):
            rep_check_asset_storage = getattr(cls, 'check_asset_storage')
            data = re.sub(check_asset_storage_pattern, rep_check_asset_storage, data)
        return data

    @classmethod
    def rep_asset_amount(cls, data):
        """
        替换资产数量
        :param data:
        :return:
        """
        second_amount_pattern = re.compile(eval(cls.re_config("asset", "second_amount")))
        third_amount_pattern = re.compile(eval(cls.re_config("asset", "third_amount")))
        fourth_amount_pattern = re.compile(eval(cls.re_config("asset", "fourth_amount")))
        asset_mysql = AssetMysql()
        asset_amount = asset_mysql.get_asset_amount()
        if re.search(second_amount_pattern, data):
            rep_second_amount = asset_amount[0].get('amount')
            data = re.sub(second_amount_pattern, str(rep_second_amount-1), data)
        if re.search(third_amount_pattern, data):
            rep_third_amount = asset_amount[1].get('amount')
            data = re.sub(third_amount_pattern, str(rep_third_amount-2), data)
        if re.search(fourth_amount_pattern, data):
            rep_fourth_amount = asset_amount[2].get('amount')
            data = re.sub(fourth_amount_pattern, str(rep_fourth_amount-3), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_unlock_asset_id(cls, data):
        """
        替换非转移锁定状态资产ID
        :param data:
        :return:
        """
        asset_id_1_pattern = re.compile(eval(cls.re_config("asset", "asset_id_1")))
        asset_id_2_pattern = re.compile(eval(cls.re_config("asset", "asset_id_2")))
        asset_id_3_pattern = re.compile(eval(cls.re_config("asset", "asset_id_3")))
        asset_id_4_pattern = re.compile(eval(cls.re_config("asset", "asset_id_4")))
        asset_mysql = AssetMysql()
        asset_id = asset_mysql.get_unlock_asset_id()
        if re.search(asset_id_1_pattern, data):
            rep_asset_id = asset_id[0].get('assets_id')
            data = re.sub(asset_id_1_pattern, str(rep_asset_id), data)
        if re.search(asset_id_2_pattern, data):
            rep_asset_id = asset_id[1].get('assets_id')
            data = re.sub(asset_id_2_pattern, str(rep_asset_id), data)
        if re.search(asset_id_3_pattern, data):
            rep_asset_id = asset_id[2].get('assets_id')
            data = re.sub(asset_id_3_pattern, str(rep_asset_id), data)
        if re.search(asset_id_4_pattern, data):
            rep_asset_id = asset_id[3].get('assets_id')
            data = re.sub(asset_id_4_pattern, str(rep_asset_id), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_lock_asset_id(cls, data):
        """
        替换转移锁定状态资产ID和资产编码
        :param data:
        :return:
        """
        lock_asset_id_pattern = re.compile(eval(cls.re_config("asset", "lock_asset_id")))
        lock_asset_encoding_pattern = re.compile(eval(cls.re_config("asset", "lock_asset_encoding")))
        asset_mysql = AssetMysql()
        asset_id_encoding = asset_mysql.get_lock_asset_id()
        if re.search(lock_asset_id_pattern, data):
            rep_asset_id = asset_id_encoding.get('assets_id')
            data = re.sub(lock_asset_id_pattern, str(rep_asset_id), data)
        if re.search(lock_asset_encoding_pattern, data):
            rep_asset_encoding = asset_id_encoding.get('assets_encoding')
            data = re.sub(lock_asset_encoding_pattern, str(rep_asset_encoding), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_transfer_id(cls, state, data):
        """
        替换资产转移列表的id
        :param state:
        :return:
        """
        transfer_id_1_pattern = re.compile(eval(cls.re_config("asset", "transfer_id_1")))
        transfer_id_2_pattern = re.compile(eval(cls.re_config("asset", "transfer_id_2")))
        transfer_id_3_pattern = re.compile(eval(cls.re_config("asset", "transfer_id_3")))
        perfected_id_pattern = re.compile(eval(cls.re_config("asset", "perfected_id")))
        asset_mysql = AssetMysql()
        transfer_id = asset_mysql.get_id_from_transfer_list(state)[0]
        perfected_id = asset_mysql.get_id_from_transfer_list(state)[1]
        if re.search(transfer_id_1_pattern, data):
            rep_asset_id = transfer_id[0].get('id')
            data = re.sub(transfer_id_1_pattern, str(rep_asset_id), data)
        if re.search(transfer_id_2_pattern, data):
            rep_asset_id = transfer_id[1].get('id')
            data = re.sub(transfer_id_2_pattern, str(rep_asset_id), data)
        if re.search(transfer_id_3_pattern, data):
            rep_asset_id = transfer_id[2].get('id')
            data = re.sub(transfer_id_3_pattern, str(rep_asset_id), data)
        if re.search(perfected_id_pattern, data):
            rep_asset_id = perfected_id[0].get('id')
            data = re.sub(perfected_id_pattern, str(rep_asset_id), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_transfer_record(cls, data):
        """
        替换资产转移列表的记录
        :param state:
        :return:
        """
        transfer_asset_class_pattern = re.compile(eval(cls.re_config("asset", "transfer_asset_class")))
        transfer_ori_depart_id_pattern = re.compile(eval(cls.re_config("asset", "transfer_ori_depart_id")))
        transfer_new_depart_id_pattern = re.compile(eval(cls.re_config("asset", "transfer_new_depart_id")))
        transfer_asset_name_pattern = re.compile(eval(cls.re_config("asset", "transfer_asset_name")))
        transfer_ori_address_id_pattern = re.compile(eval(cls.re_config("asset", "transfer_ori_address_id")))
        transfer_new_address_id_pattern = re.compile(eval(cls.re_config("asset", "transfer_new_address_id")))
        transfer_ori_code_pattern = re.compile(eval(cls.re_config("asset", "transfer_ori_code")))
        transfer_new_code_pattern = re.compile(eval(cls.re_config("asset", "transfer_new_code")))
        transfer_state_pattern = re.compile(eval(cls.re_config("asset", "transfer_state")))
        asset_mysql = AssetMysql()
        transfer_info = asset_mysql.get_transfer_record()
        if re.search(transfer_asset_class_pattern, data):
            rep_transfer_info = transfer_info.get('asset_classification')
            data = re.sub(transfer_asset_class_pattern, str(rep_transfer_info), data)
        if re.search(transfer_ori_depart_id_pattern, data):
            rep_transfer_info = transfer_info.get('original_department_id')
            data = re.sub(transfer_ori_depart_id_pattern, str(rep_transfer_info), data)
        if re.search(transfer_new_depart_id_pattern, data):
            rep_transfer_info = transfer_info.get('new_department_id')
            data = re.sub(transfer_new_depart_id_pattern, str(rep_transfer_info), data)
        if re.search(transfer_asset_name_pattern, data):
            rep_transfer_info = transfer_info.get('asset_name')
            data = re.sub(transfer_asset_name_pattern, str(rep_transfer_info), data)
        if re.search(transfer_ori_address_id_pattern, data):
            rep_transfer_info = transfer_info.get('original_storage_address')
            data = re.sub(transfer_ori_address_id_pattern, str(rep_transfer_info), data)
        if re.search(transfer_new_address_id_pattern, data):
            rep_transfer_info = transfer_info.get('new_storage_address')
            data = re.sub(transfer_new_address_id_pattern, str(rep_transfer_info), data)
        if re.search(transfer_state_pattern, data):
            rep_transfer_info = transfer_info.get('state')
            data = re.sub(transfer_state_pattern, str(rep_transfer_info), data)
        if re.search(transfer_ori_code_pattern, data):
            rep_transfer_info = transfer_info.get('original_code')
            data = re.sub(transfer_ori_code_pattern, str(rep_transfer_info), data)
        if re.search(transfer_new_code_pattern, data):
            rep_transfer_info = transfer_info.get('new_code')
            data = re.sub(transfer_new_code_pattern, str(rep_transfer_info), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_transfer_apply(cls, data):
        """
        替换资产异动-资产转移申请记录
        :param data:
        :return:
        """
        trans_out_area_pattern = re.compile(eval(cls.re_config("asset", "trans_out_area")))
        trans_out_dept_pattern = re.compile(eval(cls.re_config("asset", "trans_out_dept")))
        trans_state_pattern = re.compile(eval(cls.re_config("asset", "trans_state")))
        trans_in_area_pattern = re.compile(eval(cls.re_config("asset", "trans_in_area")))
        trans_in_dept_pattern = re.compile(eval(cls.re_config("asset", "trans_in_dept")))
        trans_in_address_pattern = re.compile(eval(cls.re_config("asset", "trans_in_address")))
        trans_start_date_pattern = re.compile(eval(cls.re_config("asset", "trans_start_date")))
        trans_end_date_pattern = re.compile(eval(cls.re_config("asset", "trans_end_date")))
        asset_mysql = AssetMysql()
        transfer_info = asset_mysql.get_transfer_apply_list()
        if re.search(trans_out_area_pattern, data):
            rep_transfer_info = transfer_info.get('transfer_out_area')
            data = re.sub(trans_out_area_pattern, str(rep_transfer_info), data)
        if re.search(trans_out_dept_pattern, data):
            rep_transfer_info = transfer_info.get('transfer_out_dept')
            data = re.sub(trans_out_dept_pattern, str(rep_transfer_info), data)
        if re.search(trans_state_pattern, data):
            rep_transfer_info = transfer_info.get('state')
            data = re.sub(trans_state_pattern, str(rep_transfer_info), data)
        if re.search(trans_in_area_pattern, data):
            rep_transfer_info = transfer_info.get('transfer_in_area')
            data = re.sub(trans_in_area_pattern, str(rep_transfer_info), data)
        if re.search(trans_in_dept_pattern, data):
            rep_transfer_info = transfer_info.get('transfer_in_dept')
            data = re.sub(trans_in_dept_pattern, str(rep_transfer_info), data)
        if re.search(trans_in_address_pattern, data):
            rep_transfer_info = transfer_info.get('new_address_id')
            data = re.sub(trans_in_address_pattern, str(rep_transfer_info), data)
        if re.search(trans_start_date_pattern, data):
            rep_transfer_info = transfer_info.get('apply_date')
            data = re.sub(trans_start_date_pattern, str(rep_transfer_info), data)
        if re.search(trans_end_date_pattern, data):
            rep_transfer_info = transfer_info.get('end_date')
            data = re.sub(trans_end_date_pattern, str(rep_transfer_info), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_transfer_change(cls, data):
        """
        替换资产异动-资产转移申请记录
        :param data:
        :return:
        """
        not_com_asset_id_pattern = re.compile(eval(cls.re_config("asset", "not_com_asset_id")))
        is_com_asset_id_pattern = re.compile(eval(cls.re_config("asset", "is_com_asset_id")))
        lock_not_com_asset_id_pattern = re.compile(eval(cls.re_config("asset", "lock_not_com_asset_id")))
        lock_not_com_asset_encoding_pattern = re.compile(eval(cls.re_config("asset", "lock_not_com_asset_encoding")))
        rand_com_asset_class_id_pattern = re.compile(eval(cls.re_config("asset", "rand_com_asset_class_id")))
        asset_mysql = AssetMysql()
        asset_id_info = asset_mysql.get_transfer_change()
        if re.search(not_com_asset_id_pattern, data):
            rep_asset_id = asset_id_info[0][0].get('assets_id')
            data = re.sub(not_com_asset_id_pattern, str(rep_asset_id), data)
        if re.search(is_com_asset_id_pattern, data):
            rep_asset_id = asset_id_info[1][0].get('assets_id')
            data = re.sub(is_com_asset_id_pattern, str(rep_asset_id), data)
        if re.search(lock_not_com_asset_id_pattern, data):
            rep_asset_id = asset_id_info[2][0].get('assets_id')
            data = re.sub(lock_not_com_asset_id_pattern, str(rep_asset_id), data)
        if re.search(lock_not_com_asset_encoding_pattern, data):
            rep_asset_encoding = asset_id_info[2][0].get('assets_encoding')
            data = re.sub(lock_not_com_asset_encoding_pattern, str(rep_asset_encoding), data)
        if re.search(rand_com_asset_class_id_pattern, data):
            rep_rand_com_asset_class_id = select_random_item([86,87,88,89,90])
            data = re.sub(rand_com_asset_class_id_pattern, str(rep_rand_com_asset_class_id), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_transfer_apply_id(cls, data):
        """
        替换资产异动-资产转移记录id
        :param data:
        :return:
        """
        transfer_apply_id_pattern = re.compile(eval(cls.re_config("asset", "transfer_apply_id")))
        transfer_apply_id_1_pattern = re.compile(eval(cls.re_config("asset", "transfer_apply_id_1")))
        transfer_apply_id_2_pattern = re.compile(eval(cls.re_config("asset", "transfer_apply_id_2")))
        asset_mysql = AssetMysql()
        transfer_apply_id = asset_mysql.get_transfer_apply_id()
        if re.search(transfer_apply_id_pattern, data):
            rep_transfer_apply_id = getattr(cls, 'transfer_apply_id')
            data = re.sub(transfer_apply_id_pattern, str(rep_transfer_apply_id), data)
        if re.search(transfer_apply_id_1_pattern, data):
            rep_transfer_apply_id = transfer_apply_id[0].get('id')
            data = re.sub(transfer_apply_id_1_pattern, str(rep_transfer_apply_id), data)
        if re.search(transfer_apply_id_2_pattern, data):
            rep_transfer_apply_id = transfer_apply_id[1].get('id')
            data = re.sub(transfer_apply_id_2_pattern, str(rep_transfer_apply_id), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_foreseen_user_name_id(cls, data):
        """
        替换资产存储表的使用人用户名和用户id
        :param data:
        :return:
        """
        foreseen_user_name_pattern = re.compile(eval(cls.re_config("asset", "foreseen_user_name")))
        foreseen_user_id_pattern = re.compile(eval(cls.re_config("asset", "foreseen_user_id")))
        if re.search(foreseen_user_name_pattern, data):
            rep_foreseen_user_name = getattr(cls, 'foreseen_user_name')
            data = re.sub(foreseen_user_name_pattern, str(rep_foreseen_user_name), data)
        if re.search(foreseen_user_id_pattern, data):
            rep_foreseen_user_id = getattr(cls, 'foreseen_user_id')
            data = re.sub(foreseen_user_id_pattern, str(rep_foreseen_user_id), data)
        return data

    @classmethod
    def rep_repair_apply_info(cls, data):
        """
        替换异动列表-维修列表申请信息
        :param data:
        :param type:
        :return:
        """
        re_create_by_pattern = re.compile(eval(cls.re_config("asset", "re_create_by")))
        re_state_pattern = re.compile(eval(cls.re_config("asset", "re_state")))
        re_send_to_person_pattern = re.compile(eval(cls.re_config("asset", "re_send_to_person")))
        re_send_to_dept_pattern = re.compile(eval(cls.re_config("asset", "re_send_to_dept")))
        re_apply_start_date_pattern = re.compile(eval(cls.re_config("asset", "re_apply_start_date")))
        re_apply_end_date_pattern = re.compile(eval(cls.re_config("asset", "re_apply_end_date")))
        asset_mysql = AssetMysql()
        repair_apply = asset_mysql.get_repair_scrap_apply(1)
        if re.search(re_create_by_pattern, data):
            rep_repair_info = repair_apply['create_by']
            data = re.sub(re_create_by_pattern, str(rep_repair_info), data)
        if re.search(re_state_pattern, data):
            rep_repair_info = repair_apply['state']
            data = re.sub(re_state_pattern, str(rep_repair_info), data)
        if re.search(re_send_to_person_pattern, data):
            rep_repair_info = repair_apply['present_jobnumber']
            data = re.sub(re_send_to_person_pattern, str(rep_repair_info), data)
        if re.search(re_send_to_dept_pattern, data):
            rep_repair_info = repair_apply['department_id']
            data = re.sub(re_send_to_dept_pattern, str(rep_repair_info), data)
        if re.search(re_apply_start_date_pattern, data):
            rep_repair_info = repair_apply['application_date']
            data = re.sub(re_apply_start_date_pattern, str(rep_repair_info), data)
        if re.search(re_apply_end_date_pattern, data):
            rep_repair_info = repair_apply['application_date']
            data = re.sub(re_apply_end_date_pattern, str(rep_repair_info), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_scrap_apply_info(cls, data):
        """
        替换异动列表-报废列表申请信息
        :param data:
        :param type:
        :return:
        """
        sc_create_by_pattern = re.compile(eval(cls.re_config("asset", "sc_create_by")))
        sc_state_pattern = re.compile(eval(cls.re_config("asset", "sc_state")))
        sc_send_to_person_pattern = re.compile(eval(cls.re_config("asset", "sc_send_to_person")))
        sc_send_to_dept_pattern = re.compile(eval(cls.re_config("asset", "sc_send_to_dept")))
        sc_apply_start_date_pattern = re.compile(eval(cls.re_config("asset", "sc_apply_start_date")))
        sc_apply_end_date_pattern = re.compile(eval(cls.re_config("asset", "sc_apply_end_date")))
        asset_mysql = AssetMysql()
        scrap_apply = asset_mysql.get_repair_scrap_apply(2)
        if re.search(sc_create_by_pattern, data):
            rep_scrap_info = scrap_apply['create_by']
            data = re.sub(sc_create_by_pattern, str(rep_scrap_info), data)
        if re.search(sc_state_pattern, data):
            rep_scrap_info = scrap_apply['state']
            data = re.sub(sc_state_pattern, str(rep_scrap_info), data)
        if re.search(sc_send_to_person_pattern, data):
            rep_scrap_info = scrap_apply['present_jobnumber']
            data = re.sub(sc_send_to_person_pattern, str(rep_scrap_info), data)
        if re.search(sc_send_to_dept_pattern, data):
            rep_scrap_info = scrap_apply['department_id']
            data = re.sub(sc_send_to_dept_pattern, str(rep_scrap_info), data)
        if re.search(sc_apply_start_date_pattern, data):
            rep_scrap_info = scrap_apply['application_date']
            data = re.sub(sc_apply_start_date_pattern, str(rep_scrap_info), data)
        if re.search(sc_apply_end_date_pattern, data):
            rep_scrap_info = scrap_apply['application_date']
            data = re.sub(sc_apply_end_date_pattern, str(rep_scrap_info), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def rep_repair_scrap_apply_id(cls, data):
        """
        替换资产异动-资产维修、报废记录id
        :param data:
        :return:
        """
        repair_apply_id_1_pattern = re.compile(eval(cls.re_config("asset", "repair_apply_id_1")))
        repair_apply_id_2_pattern = re.compile(eval(cls.re_config("asset", "repair_apply_id_2")))
        scrap_apply_id_1_pattern = re.compile(eval(cls.re_config("asset", "scrap_apply_id_1")))
        scrap_apply_id_2_pattern = re.compile(eval(cls.re_config("asset", "scrap_apply_id_2")))
        asset_mysql = AssetMysql()
        repair_scrap_apply_id = asset_mysql.get_repair_scrap_apply_id()
        if re.search(repair_apply_id_1_pattern, data):
            rep_repair_apply_id = repair_scrap_apply_id[0].get('id')
            data = re.sub(repair_apply_id_1_pattern, str(rep_repair_apply_id), data)
        if re.search(repair_apply_id_2_pattern, data):
            rep_repair_apply_id = repair_scrap_apply_id[1].get('id')
            data = re.sub(repair_apply_id_2_pattern, str(rep_repair_apply_id), data)
        if re.search(scrap_apply_id_1_pattern, data):
            rep_scrap_apply_id = repair_scrap_apply_id[2].get('id')
            data = re.sub(scrap_apply_id_1_pattern, str(rep_scrap_apply_id), data)
        if re.search(scrap_apply_id_2_pattern, data):
            rep_scrap_apply_id = repair_scrap_apply_id[3].get('id')
            data = re.sub(scrap_apply_id_2_pattern, str(rep_scrap_apply_id), data)
        asset_mysql.close_sql()
        return data

    @classmethod
    def asset_id_parameterize(cls, data):
        """
        资产id数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = cls.rep_asset_id(data)
        return data

    @classmethod
    def import_asset_parameterize(cls, data):
        """
        导入资产数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = cls.rep_check_asset_storage(data)
        return data

    @classmethod
    def asset_parameterize(cls, data):
        """
        资产数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = UserContext.rep_bessky_info(data)
        data = UserContext.rep_ordinary_user_info(data)
        data = cls.rep_asset_class_info(data)
        data = cls.rep_dept_area(data)
        data = cls.rep_dept_area_id(data)
        data = cls.rep_asset_info(data)
        return data

    @classmethod
    def add_asset_parameterize(cls, data):
        """
        添加资产数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = cls.rep_bottom_asset_class(data)
        data = cls.rep_user_dept_emp(data)
        data = cls.rep_dept_area(data)
        data = cls.rep_asset_state(data)
        data = cls.rep_unmatched_user_dept_emp(data)
        data = cls.rep_err_emp_num(data)
        return data

    @classmethod
    def edit_asset_parameterize(cls, data):
        """
        编辑资产数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = cls.rep_bottom_asset_class(data)
        data = cls.rep_user_dept_emp(data)
        data = cls.rep_dept_area(data)
        data = cls.rep_asset_state(data)
        data = cls.rep_asset_id(data)
        data = cls.rep_unmatched_user_dept_emp(data)
        data = cls.rep_err_emp_num(data)
        return data

    @classmethod
    def del_asset_parameterize(cls, data):
        """
        删除资产数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = UserContext.rep_bessky_info(data)
        data = UserContext.rep_ordinary_user_info(data)
        data = cls.rep_bottom_asset_class(data)
        data = cls.rep_user_dept_emp(data)
        data = cls.rep_dept_area(data)
        data = cls.rep_asset_state(data)
        data = cls.rep_asset_id(data)
        data = cls.rep_lock_asset_id(data)
        # data = cls.rep_asset_encoding(data)
        return data

    @classmethod
    def inventory_asset_parameterize(cls, data):
        """
        盘点导入数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = cls.rep_asset_amount(data)
        return data

    @classmethod
    def batch_transfer_parameterize(cls, data):
        """
        批量转移数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = cls.rep_unlock_asset_id(data)
        data = cls.rep_lock_asset_id(data)
        data = cls.rep_dept_area(data)
        data = cls.rep_cur_emp_num(data)
        return data

    @classmethod
    def export_parameterize(cls, data):
        """
        导出数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = cls.rep_asset_info(data)
        return data

    @classmethod
    def batch_confirm_print_parameterize(cls, data):
        """
        批量确认打印状态数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = cls.rep_unlock_asset_id(data)
        return data

    @classmethod
    def batch_operate_parameterize(cls, state, data):
        """
        批量完善数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = cls.rep_transfer_id(state, data)
        data = cls.rep_dept_area(data)
        data = cls.rep_cur_emp_num(data)
        return data

    @classmethod
    def transfer_record_parameterize(cls, data):
        """
        资产转移数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = cls.rep_transfer_record(data)
        return data

    @classmethod
    def transfer_apply_parameterize(cls, data):
        """
        异动列表-资产转移申请数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_bessky_info(data)
        data = cls.rep_transfer_apply(data)
        return data

    @classmethod
    def create_batch_transfer_parameterize(cls, data, n=0):
        """
        异动列表-新建批量转移数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = ContextHandle.rep_day_after(data, n)
        data = cls.rep_user_dept_emp(data)
        data = cls.rep_foreseen_user_name_id(data)
        data = cls.rep_bottom_asset_class(data)
        data = cls.rep_asset_state(data)
        data = cls.rep_asset_id(data)
        data = cls.rep_unlock_asset_id(data)
        data = cls.rep_dept_area(data)
        data = cls.rep_cur_emp_num(data)
        data = cls.rep_transfer_change(data)
        return data

    @classmethod
    def edit_batch_transfer_parameterize(cls, data, n=0):
        """
        异动列表-编辑批量转移数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = ContextHandle.rep_day_after(data, n)
        data = cls.rep_dept_area(data)
        data = cls.rep_cur_emp_num(data)
        data = cls.rep_transfer_apply_id(data)
        return data

    @classmethod
    def approve_batch_transfer_parameterize(cls, data, n=0):
        """
        异动列表-审批批量转移数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = ContextHandle.rep_day_after(data, n)
        data = cls.rep_dept_area(data)
        data = cls.rep_asset_state(data)
        data = cls.rep_cur_emp_num(data)
        data = cls.rep_transfer_apply_id(data)
        data = cls.rep_transfer_change(data)
        return data

    @classmethod
    def view_batch_transfer_detail_parameterize(cls, data):
        """
        异动列表-查看批量转移详情数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = cls.rep_transfer_apply_id(data)
        return data

    @classmethod
    def search_repair_scrap_list_parameterize(cls, data):
        """
        异动列表-维修/报废列表查询数据参数化
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_bessky_info(data)
        data = cls.rep_repair_apply_info(data)
        data = cls.rep_scrap_apply_info(data)
        return data

    @classmethod
    def edit_batch_repair_scrap_parameterize(cls, data):
        """
        异动列表-编辑批量维修/报废数据参数化
        :param data:
        :return:
        """
        if isinstance(data, dict):
            data = json.dumps(data)
        data = UserContext.rep_admin_user_info(data)
        data = cls.rep_dept_area(data)
        data = cls.rep_cur_emp_num(data)
        data = cls.rep_repair_scrap_apply_id(data)
        return data

if __name__ == '__main__':
    yaml_obj = YamlHandle(ASSET_MANAGE_YAML)
    yaml_data = yaml_obj.get_data('batch_transfer')
    data_before = yaml_data[0]
    data_after = AssetContextHandle.batch_transfer_parameterize(data_before)
    print(f"参数化前：{data_before}\n参数化后：{data_after}")


